# export INFLUXDB_TOKEN=sP2EPEmTQ5O5JKB7b5CNOYKbJe_hsmgaoP61hIrVS1jxptoyiNjmJyApGnGePXtUs-Q_hFvMRQCfXhWbyvrXCg==



import influxdb_client, os, time
from influxdb_client import InfluxDBClient, Point, WritePrecision
from influxdb_client.client.write_api import SYNCHRONOUS

token = 'sP2EPEmTQ5O5JKB7b5CNOYKbJe_hsmgaoP61hIrVS1jxptoyiNjmJyApGnGePXtUs-Q_hFvMRQCfXhWbyvrXCg=='
org = "media"
url = "http://localhost:8086"

write_client = influxdb_client.InfluxDBClient(url=url, token=token, org=org)


bucket="lims"

write_api = write_client.write_api(write_options=SYNCHRONOUS)

'''
Map<String, String> tags = new HashMap<>();
        tags.put("设备","虚拟设备4");
        tags.put("工位","工位1");
        tags.put("日期", DateUtil.today());

        Map<String,Object> fields = new HashMap<>();
        fields.put("电流",30.00);
        fields.put("电压",175.23);
        fields.put("温度",25.4);
        bean.insert("actValWbl1",tags,fields);

'''

# 获取当天的日期
today = time.strftime("%Y-%m-%d")
print(today)

for value in range(5):
    # 数值value转换为字符串
    def int2str(value):
        return str(value)
    # 数值value转换为float
    def int2float(value):
        return float(value)
    point = (
        Point("actValWbl1")
        .tag("设备", "虚拟设备2")
        .tag("工位", "工位1")
        .tag("日期", today)
        .field("电流", int2float(value))
        .field("电压", int2float(value))
        .field("温度", int2float(value))
    )
    write_api.write(bucket=bucket, org="media", record=point)
    time.sleep(1) # separate points by 1 second
